home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / comm / converse.sit / NSCA Converse / Patient < prev    next >
Text File  |  1991-04-01  |  7KB  |  322 lines

  1. program Patient;
  2.     uses
  3.         PatientDoctorRelations, Sound;
  4.  
  5.     const
  6.         FilterOK = 4;
  7.         FilterCancel = 5;
  8.         NetworkEvent = 101;
  9.         DoctorModeEvent = 102;
  10.  
  11.         MessageListID = 128;
  12.         SplashAboutID = 256;
  13.  
  14.     var
  15.         cancel: boolean;
  16.         DoctorMode: boolean;
  17.         theKeys: KeyMap;
  18.         MyTime: longint;
  19.     var
  20.         D: DialogPtr;
  21.         item: integer;
  22.  
  23. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  24.  
  25.     function UserInterrupt: boolean;
  26.         var
  27.             myEvent: EventRecord;
  28.     begin
  29.         UserInterrupt := false;
  30.         if GetNextEvent(keyDownMask, myEvent) then
  31.             if BitAnd(myEvent.message, charCodeMask) = 46 then
  32.                 if (BitAnd(myEvent.modifiers, cmdKey) = cmdKey) then
  33.                     UserInterrupt := true;
  34.     end;
  35.  
  36. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  37. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  38.  
  39.     procedure GetDText (D: DialogPtr; item: integer; var Str: Str255);
  40.         var
  41.             itemHandle: Handle;
  42.             itemType: integer;
  43.             itemRect: Rect;
  44.     begin
  45.         GetDItem(D, item, itemType, itemHandle, itemRect);
  46.         GetIText(itemHandle, str);
  47.     end;
  48.  
  49. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  50.  
  51.     procedure SetDText (D: DialogPtr; item: integer; Str: Str255);
  52.         var
  53.             itemHandle: Handle;
  54.             itemType: integer;
  55.             itemRect: Rect;
  56.     begin
  57.         GetDItem(D, item, itemType, itemHandle, itemRect);
  58.         SetIText(itemHandle, str);
  59.     end;
  60.  
  61. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  62.  
  63.     function JLDLOGFilter (D: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  64.         var
  65.             ch, key: integer;
  66.             time: longint;
  67.             OK: boolean;
  68.             itemHandle: handle;
  69.             itemType: integer;
  70.             itemRect: Rect;
  71.             pState: PenState;
  72.             OldPort: GrafPtr;
  73.             NWEvent: EventRecord;
  74.             hh: handle;
  75.     begin
  76.         JLDLOGFilter := false;
  77.         with theEvent do
  78.             case theEvent.what of
  79.                 KeyDown: 
  80.                     begin
  81.                         OK := false;
  82.                         ch := BitAnd(theEvent.message, charCodeMask);
  83.                         key := BitAnd(BitShift(theEvent.message, -8), charCodeMask);
  84.                         if ((key = 76) and (BitAnd(modifiers, cmdKey) = cmdKey) and (BitAnd(modifiers, optionKey) = optionKey)) then
  85.                             begin
  86.                                 itemHit := DoctorModeEvent;
  87.                                 JLDLOGFilter := true;
  88.                             end
  89.                         else if (ch in [$0D, $03]) and (FilterOK <> -1) and not (BitAnd(modifiers, ShiftKey) = ShiftKey) then
  90.                             begin
  91.                                 itemHit := FilterOK;
  92.                                 OK := true;
  93.                             end
  94.                         else if (key = $35) and (FilterCancel <> -1) then
  95.                             begin
  96.                                 itemHit := FilterCancel;
  97.                                 OK := true;
  98.                             end;
  99.                         if OK then
  100.                             begin
  101.                                 GetDItem(D, itemHit, itemType, itemHandle, itemRect);
  102.                                 if (itemType = ctrlItem + btnCtrl) then
  103.                                     begin
  104.                                         JLDLOGFilter := true;
  105.                                         HiliteControl(ControlHandle(itemHandle), 1);
  106.                                         delay(5, time);
  107.                                         HiliteControl(ControlHandle(itemHandle), 0);
  108.                                     end;
  109.                             end;
  110.                     end;
  111.                 otherwise
  112.                     begin
  113.                         if GetNextEvent(networkMask, NWEvent) then
  114.                             begin
  115.                                 JLDLOGFilter := true;
  116.                                 itemHit := NetworkEvent;
  117.                             end;
  118.                     end;
  119.             end;
  120.     end;
  121.  
  122. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  123. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  124.  
  125.     procedure About;
  126.         var
  127.             D: DialogPtr;
  128.             item: integer;
  129.     begin
  130.         D := GetNewDialog(SplashAboutID, nil, Pointer(-1));
  131.         ModalDialog(nil, item);
  132.         DisposDialog(D);
  133.     end;
  134.  
  135. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  136. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  137.  
  138.     function Hospital: boolean;
  139.         const
  140.             DLOGID = 128;
  141.             PatientEdit = 1;
  142.             MsgStatic = 2;
  143.             DrStatic = 3;
  144.             OKButton = 4;
  145.             QuitButton = 5;
  146.             Aboutbutton = 7;
  147.             FirstButton = 8;
  148.             LastButton = 22;
  149.         var
  150.             D: DialogPtr;
  151.             item, itemToSelect: integer;
  152.             DLogDone: boolean;
  153.             S, Response: Str255;
  154.  
  155. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  156.  
  157.         procedure GoToDoctorMode;
  158.         begin
  159.             if not DoctorMode then
  160.                 SizeWindow(D, 504, 192, true)
  161.             else
  162.                 SizeWindow(D, 504, 156, true);
  163.             DoctorMode := not DoctorMode;
  164.         end;
  165.  
  166. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  167.  
  168.         procedure InitializeDialog;
  169.             var
  170.                 Hahaha: handle;
  171.         begin
  172.             if DoctorMode then
  173.                 begin
  174.                     Hahaha := GetResource('snd ', 5009);
  175.                     if (SndPlay(nil, Hahaha, false) <> 0) then
  176.                         begin
  177.                         end;
  178.                     disposHandle(Hahaha);
  179.                     DoctorMode := false;
  180.                     GoToDoctorMode;
  181.                 end;
  182.             SetDText(D, PatientEdit, '');
  183.             DLogDone := false;
  184.             StartRead;
  185.         end;
  186.  
  187. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  188.  
  189.         procedure LetDoctorTalk;
  190.         begin
  191.             hear(response);
  192.             if (Copy(response, 1, 1) = '*') then
  193.                 begin
  194.                     response := Copy(response, 2, length(response) - 1);
  195.                     Sysbeep(0);
  196.                 end;
  197.             if DoctorMode then
  198.                 begin{I am the doctor}
  199.                     SetDText(D, MsgStatic, 'The patient says:');
  200.                     SetDText(D, DrStatic, response);
  201.                 end{I am the doctor}
  202.             else
  203.                 begin{I am the patient}
  204.                     SetDText(D, MsgStatic, '');
  205.                     SetDText(D, DrStatic, response);
  206.                 end;{I am the patient}
  207.             StartRead;
  208.         end;
  209.  
  210. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  211.  
  212.         procedure PatientIsDoneTalking;
  213.         begin
  214.             GetDText(D, PatientEdit, S);
  215.             if DoctorMode then
  216.                 talk(S)
  217.             else
  218.                 begin
  219.                     talk(Concat('*', S));
  220.                     SetDText(D, MsgStatic, 'Hmmm...');
  221.                     SetDText(D, DrStatic, '');
  222.                 end;
  223.             SetDText(D, PatientEdit, '');
  224.             itemToSelect := PatientEdit;
  225.         end;
  226.  
  227. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  228.  
  229.         procedure ListenToPatient;
  230.             var
  231.                 extra: integer;
  232.         begin
  233.             if DoctorMode then
  234.                 begin
  235.                 end
  236.             else
  237.                 begin
  238.                     GetDText(D, PatientEdit, S);
  239.                     talk(S);
  240.                 end;
  241.         end;
  242.  
  243. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  244.  
  245.         procedure ExecuteButton (index: integer);
  246.             var
  247.                 S: Str255;
  248.         begin
  249.             GetIndString(S, MessageListID, index + 1);
  250.             SetDText(D, PatientEdit, S);
  251.         end;
  252.  
  253. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  254.  
  255.     begin
  256.         D := GetNewDialog(DlogID, nil, Pointer(-1));
  257.         InitializeDialog;
  258.         itemToSelect := PatientEdit;
  259.         repeat
  260.             if itemToSelect <> 0 then
  261.                 SelIText(D, itemToSelect, 0, 32767);
  262.             itemToSelect := 0;
  263.             ModalDialog(@JLDLOGFilter, item);
  264.             case item of
  265.                 OKButton: 
  266.                     PatientIsDoneTalking;
  267.                 QuitButton: 
  268.                     begin
  269.                         Hospital := true;
  270.                         DLogDone := true;
  271.                         if not DoctorMode then
  272.                             talk('<<Quitting>>');
  273.                     end;
  274.                 AboutButton: 
  275.                     About;
  276.                 NetworkEvent: 
  277.                     LetDoctorTalk;
  278.                 DoctorModeEvent: 
  279.                     GoToDoctorMode;
  280.                 PatientEdit: 
  281.                     ListenToPatient;
  282.                 otherwise
  283.                     if (item >= FirstButton) and (item <= lastButton) then
  284.                         ExecuteButton(item - FirstButton);
  285.             end;
  286.         until DLogDone;
  287.         DisposDialog(D);
  288.     end;
  289.  
  290. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  291. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  292. {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  293.  
  294. begin
  295.     GetKeys(theKeys);
  296.     SetCursor(GetCursor(WatchCursor)^^);
  297.     D := GetNewDialog(SplashAboutID, nil, Pointer(-1));
  298.     DrawDialog(D);
  299.     MyTime := TickCount + 60;
  300. {Ñ DoctorMode := (theKeys[$7A] and theKeys[$76] and theKeys[$61] and theKeys[$62]);Ñ}
  301.     DoctorMode := (theKeys[$7A]);
  302.  
  303.     OpenSocket;
  304.     Cancel := false;
  305.     while not GetAddress and not Cancel do
  306.         begin
  307.             Cancel := UserInterrupt;
  308.         end;
  309.  
  310.     repeat
  311.     until (tickCount > MyTime);
  312.     DisposDialog(D);
  313.  
  314.     if not Cancel then
  315.         begin
  316.             InitCursor;
  317.             if Hospital then
  318.                 begin
  319.                 end;
  320.         end;
  321.     CloseSocket;
  322. end.